﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLLopHoc.DoiTuongDuLieu;
using System.Data;

namespace QLLopHoc.KetNoiDatabase
{
    public class KNChiTietLH
    {
        public static List<string> LayDSMaSVCuaLH(string tenLH)
        {
            List<string> kq = new List<string>();
            string sql = "select MSSV from ChiTietLopHoc where  TenLopHoc='" + tenLH + "'";
            DataTable dt = DataAccess.execquery(sql);
            foreach (DataRow dr in dt.Rows)
            {
                kq.Add((string)dr["MSSV"]);
            }
            return kq;
        }
        public static List<string> LayDSMaLHCuaSV(string mssv)
        {
            List<string> kq = new List<string>();
            string sql = "select TenLopHoc from ChiTietLop where  MSSV='" + mssv + "'";
            DataTable dt = DataAccess.execquery(sql);
            foreach (DataRow dr in dt.Rows)
            {
                kq.Add((string)dr["TenLopHoc"]);
            }
            return kq;
        }
        public static bool ThemChiTietLH(DTChiTietLH ctlh)
        {
            string sql = "INSERT INTO ChiTietLop(TenLopHoc,MSSV) VALUES('" + ctlh.TenLopHoc + "','" + ctlh.MSSV + "')";
            //string sql = "INSERT INTO ChiTietLop(TenLopHoc,MSSV) VALUES('" + ctlh.TenLopHoc + "','" + ctlh.MSSV + "')";
            if (DataAccess.ExecNonQuery(sql) > 0)
            {
                return true;
            }
            return false;
        }
        //Phuong thuc xoa mot chi tiet lop hoc
        public static bool XoaChiTietLH(DTChiTietLH ctlh)
        {
            string sql = "DELETE from ChiTietLop WHERE TenLopHoc='" + ctlh.TenLopHoc + "' and MSSV='" + ctlh.MSSV + "'";
            
            if (DataAccess.ExecNonQuery(sql) > 0)
            {
                return true;
            }
            return false;
        }
    }
}
